import Vue from 'vue'
import Router from 'vue-router'

import UserList from '../components/UserList'
import Home from '../components/Home'
import App from '../App'

import listBook from '../views/listBook'
import PageTwo from '../views/addBook'
import ListAddress from '../views/listaddress'
import Index from '../views/Index'
import BookUpdate from '../views/BookUpdate'
import Login from '../components/Login'
import Register from '../components/Register'

import Welcome from '../components/Welcome'

import PageFour from '../views/PageFour'

import ManageHome from '../views/ManageHome'

Vue.use(Router)

const routes=[

  {
    path:'/navi',
    name:'图书管理',
    show:true,
    redirect:"page1",
    component:Index,
    children:[
      {
        path:'/page1',
        name:'查询图书',
        component:listBook
      },
      {
        path:'/page2',
        name:'添加图书',
        component:PageTwo
      },
      {
        path:'/bookupdate',
        name:'修改书籍',
        show:false,
        component:BookUpdate
      }

    ]
  },


  {
    path:'/navigation',
    name:'导航2',
    show:true,
    component:Index,
    children: [
      {
        path:'/listaddress',
        name:'用户列表',
        component:ListAddress
      }
    ]
  },
  {
    path:'/login',
    name:'登录页面',
    component:Login

  },
  {
    path:'/register',
    name:'注册页面',
    component:Register
  },
  {
    path:'/',
    redirect:'/login',
    name:'home页面',
    component:ManageHome
  },
  {
    path:'/managehome',
    redirect:'/welcome',
    name:'home页面',
    component:ManageHome,
    children:[
      {
        path:'/welcome',
        name:'欢迎页面',
        component:Welcome
      },
      {
      path:'/pagefour',
        name:'页面四',
        component:PageFour
      }
    ]
  }


]

const router = new Router({
  mode:'history',
  base: process.env.DATABASE_ERR,
  routes

})

//路由导航卫士
// router.beforeEach((to,form,next)=>{
//   if(to.path == '/login'){
//     next()
//
//   }else{
//     const token = window.sessionStorage.getItem('token');
//     if(!token){
//       next('\login')
//     }else{
//       next()
//     }
//
//   }
//
// })
export default router
